#define CHECK printf("CHECK"); getchar();
#include <limits.h>
#include "BFS.h"

inline int log2(int x){
    int count = 0;
    while(x>1){
        count++;
        x >>=1;
    }
    return count;
}


/// FOR DEBUGS
void show(BitVector<WORDTYPE>*word, int n){
    int i;	
    for( i = 1 ; i < n ; i++){
        if(word->isInSet(i))printf("(%d) ",i);
    }
    printf("Continue ?\n");
    getchar();
}


void bitMapBFS(Digraph *digraph, int root,void f(int )){
   int n = digraph->size;
   int v = root;

   BitVector<WORDTYPE>** adj = digraph->adj;
   BitVector<WORDTYPE>* visit = new BitVector<WORDTYPE>(n);
   visit->allToSet();
   BitVector<WORDTYPE>* suc = new BitVector<WORDTYPE>(n);
   BitVector<WORDTYPE>* queue = new BitVector<WORDTYPE>(n);
   BitVector<WORDTYPE>* aux;
   suc->toSet(root);

   while(!suc->isEmpty()){
	aux = queue;
	queue = suc;
	suc = aux;

	//printf(" \n queue \n");
	//queue->show();

	v = queue->nextSet(0);
	//printf("novo nível\n");
	while(v != -1){
		f(v);
		visit->toCompl(v);
		//printf("compl OK \n");
		//getchar();
		queue->toCompl(v);
		//printf("compl OK \n");
		//getchar();
		suc->logicor(adj[v]);
		//printf("compl OK \n");
		//getchar();
		v = queue->nextSet(v);
		//printf("compl OK \n");
		//getchar();
	}
	//printf("\n visit \n");
	//visit->show();
	//getchar();
	suc->logicand(visit);
	//printf("\n succ \n");
	//suc->show();
	//getchar();
   }
}

















